{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python374jvsc74a57bd02a7e95a32014fc1ccf24626d45a98c6e7b4373277259c22f47a91d487fc3e8a5",
   "display_name": "Python 3.7.4 64-bit ('base': conda)"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "source": [
    "## 图形用户界面GUI 入门\n",
    "> 简单易用Tkinter(执行速度慢),重型火炮pyQt(适合专业人士),折衷的wxPython支持跨平台运行 \n",
    " \n",
    "### wxPython\n",
    "组件  \n",
    "1.组件容器,用于容纳其他组件\n",
    "> wx.Panel等  \n",
    "\n",
    "2.动态组件 --- 可被用户编辑()\n",
    "> 按钮,输入框,单选/复选框,wx.ListBox等\n",
    ">>常用按钮类包括:wx.Botton文本按钮;wx.BitmapButtion位图按钮;wx.ToggleButton开关按钮\n",
    ">>输入文本框:wx.TextCtrl\n",
    "\n",
    "3.静态组件 --- 显示信息,不可被编辑(静态文本,列表框)\n",
    "> wx.StaticBitmap,wx.StaticText(静态文本框),wx.StaticLine等\n",
    "\n",
    "4.其他组件\n",
    "> wx.ToolBar,wx.MenuBar,wx.StatusBar\n",
    ">>菜单类包括:wx.MunuBar;wx.Menu;wx.MenuItem\n",
    ">>>菜单事件 wx.EVT_MENU"
   ],
   "cell_type": "markdown",
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "metadata": {},
     "execution_count": 2
    }
   ],
   "source": [
    "import wx\n",
    "\n",
    "# del app\n",
    "\n",
    "# 简要展示\n",
    "# app = wx.App()\n",
    "# frame = wx.Frame(None,title='Hello World')  # 窗体的标题栏\n",
    "# frame.Show(True)\n",
    "# app.MainLoop()\n",
    "\n",
    "# 利用面向对象思维\n",
    "class FrameDIY(wx.Frame):\n",
    "    def __init__(self,superior):\n",
    "        wx.Frame.__init__(self,parent=superior,title='Example',pos=(100,200),size=(350,200))\n",
    "        panel = wx.Panel(self)\n",
    "        text = wx.TextCtrl(panel,value='Hello World',size=(350,200))\n",
    "# 窗口层级: Frame >> Panel >> TextCtrl\n",
    "app = wx.App()\n",
    "frame = FrameDIY(None)\n",
    "frame.Show(True)\n",
    "app.MainLoop()\n"
   ]
  },
  {
   "source": [
    "### GUI程序工作的基本机制 _ 事件处理\n",
    "事件处理(用户操作触发产生)  \n",
    "> 将特定事件关联至特定代码(事件处理函数),当事件触发时相关联代码被自动执行\n",
    ">> eg.鼠标移动事件时,OnMove()方法自动调用\n",
    "\n"
   ],
   "cell_type": "markdown",
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 将鼠标左键抬起动作 与 Onclick事件关联\n",
    "import wx\n",
    "\n",
    "del app\n",
    "\n",
    "class FrameDIY(wx.Frame):\n",
    "    def __init__(self,superior):\n",
    "        wx.Frame.__init__(self,parent=superior,title='Example',pos=(100,200),size=(350,200))\n",
    "        self.panel = wx.Panel(self)\n",
    "        self.panel.Bind(wx.EVT_LEFT_UP,self.OnClick)    # 实现绑定\n",
    "    def OnClick(self,event):\n",
    "        posm = event.GetPosition()      # 获得鼠标单击位置\n",
    "        wx.StaticText(parent=self.panel,label='hello world',pos=(posm.x,posm.y))\n",
    "\n",
    "app = wx.App()\n",
    "frame = FrameDIY(None)\n",
    "frame.Show(True)\n",
    "app.MainLoop()"
   ]
  },
  {
   "source": [
    "### 布局管理 sizer\n",
    "- wx.BoxSizer\n",
    "- wx.GridSizer  所有组件大小一致,\n",
    "- wx.FlexGridSizer  组件行高,列高由组件决定\n",
    "- ..."
   ],
   "cell_type": "markdown",
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ]
}